package cn.htsyb.synergy.utils;

import java.util.HashMap;

/**
 * URL参数处理工具类
 * 
 * @author lakeside hubin_yuan.410@hotmail.com
 * @version V1.0.0
 * @since 1.0
 * @date 2022/5/11
 */
public class UrlUtil {

    /**
     * 实现将URL参数转化成Map
     *
     * @param paramStr URL Params字符串
     * @return
     */
    public static HashMap<String, String> convertParam(String paramStr) {
        HashMap<String, String> argsMap = new HashMap<String, String>();
        String[] agrs = paramStr.split("&");
        if (agrs.length > 0) {
            for (String agrStr : agrs) {
                int splitIdex = agrStr.indexOf("=");
                if (splitIdex > 0) {
                    argsMap.put(agrStr.substring(0, splitIdex), agrStr.substring(splitIdex + 1));
                }
            }
        }
        return argsMap;
    }

    /**
     * 实现将URL参数转化成Map
     *
     * @param urlStr URL Params字符串
     * @return
     */
    public static HashMap<String, String> convertURLParam(String urlStr) {
        int Idx = urlStr.indexOf("?");
        if (Idx > 0) {
            return convertParam(urlStr.substring(urlStr.indexOf("?") + 1));
        }
        return new HashMap<String, String>();
    }
}
